using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

public class C_敌人AI_LangJianKe : C_敌人AI_Base<StateType_Enemy_XiaoGuai, EnemyStateBase_LangJianKe>
{
	[HideInInspector]
	public C_活动范围 _C_活动范围;

	[HideInInspector]
	private ItemUI_EnemyHP _UI_HP;

	[HideInInspector]
	private Transform _Tsf_HP;

	private float _m连续移动撞墙次数;

	public AudioClip _AudioC_刀狼砍击;

	public AudioClip _AudioC_小妖死亡;

	public float _连续移动撞墙次数
	{
		get
		{
			return _m连续移动撞墙次数;
		}
		set
		{
			_m连续移动撞墙次数 = value;
			if (_m连续移动撞墙次数 >= 15f)
			{
				_m连续移动撞墙次数 = 0f;
				ChangeState(StateType_Enemy_XiaoGuai.站立);
				_Is虚幻 = true;
				_Is追击中 = false;
				_Tsf_玩家 = null;
				_Is视野范围内 = false;
				_SR_Model.DOFade(0f, 0.75f).OnComplete(delegate
				{
					_Is虚幻 = false;
					base.transform.position = _StartPos;
					_SR_Model.DOFade(1f, 0.5f);
				});
			}
		}
	}

	public void F_Ani_Play_AudioC_刀狼砍击()
	{
		MonoSingleton<AudioManager>.Instance.F_Play_SFX(_AudioC_刀狼砍击);
	}

	private void Start()
	{
		_C_活动范围 = GetComponentInParent<C_活动范围>();
		_Is虚幻 = false;
		_UI_HP = MonoSingleton<GameManager>.Instance.F_Get_ItemUI_EnemyHP();
		_UI_HP._可见性 = false;
		_UI_HP.F_SetVal(_Data._CurrHP, _Data._MaxHP);
		_Tsf_HP = base.transform.Find("Pos_HP");
		_C_攻击判断._伤害 = _Data._Atk;
		_C_攻击判断._击退力度 = 10f;
		_FSM.states = new Dictionary<StateType_Enemy_XiaoGuai, EnemyStateBase_LangJianKe>
		{
			{
				StateType_Enemy_XiaoGuai.站立,
				new EnemyState_LangJianKe_站立().Init(this)
			},
			{
				StateType_Enemy_XiaoGuai.散步,
				new EnemyState_LangJianKe_散步().Init(this)
			},
			{
				StateType_Enemy_XiaoGuai.追击,
				new EnemyState_LangJianKe_追击().Init(this)
			},
			{
				StateType_Enemy_XiaoGuai.攻击,
				new EnemyState_LangJianKe_攻击().Init(this)
			},
			{
				StateType_Enemy_XiaoGuai.受击,
				new EnemyState_LangJianKe_受击().Init(this)
			},
			{
				StateType_Enemy_XiaoGuai.死亡,
				new EnemyState_LangJianKe_死亡().Init(this)
			}
		};
		ChangeState(StateType_Enemy_XiaoGuai.站立);
	}

	public override void BeAttack(float atk_生命, float atk_僵直, float atk_击退力度, Vector2 atk_Pos, bool atk_Is远程 = false)
	{
		if (!_Is虚幻 && !_Is死亡)
		{
			base.BeAttack(atk_生命, atk_僵直, atk_击退力度, atk_Pos, atk_Is远程);
			_UI_HP._可见性 = true;
			base._BeAttack_Pos = atk_Pos;
			base._BeAttack_击退力度 = atk_击退力度;
			Debug.LogError($"{base.name}+{atk_生命}");
			_Data._CurrHP -= atk_生命;
			_UI_HP.F_SetVal(_Data._CurrHP, _Data._MaxHP);
			if (_Data._CurrHP <= 0f)
			{
				F_死亡_给玩家经验();
				ChangeState(StateType_Enemy_XiaoGuai.死亡);
			}
			_Data._Curr僵直数值 += atk_僵直;
			if (_Data._Curr僵直数值 >= _Data._Max僵直数值)
			{
				_Data._Curr僵直数值 = 0f;
				_Data._Max僵直数值 += _Data._僵直数值增长;
				ChangeState(StateType_Enemy_XiaoGuai.受击);
			}
		}
	}

	private void OnDestroy()
	{
		F_删除血条();
	}

	public void F_删除血条()
	{
		if (_UI_HP != null)
		{
			Object.Destroy(_UI_HP.gameObject);
			_UI_HP = null;
		}
	}

	private void LateUpdate()
	{
		if (_UI_HP != null)
		{
			_UI_HP.F_SetPos(_Tsf_HP.position);
		}
	}
}
